package java课题设计.功能类;

//OperationPage
import java课题设计.功能类.Seek.SeekStudent;
import java课题设计.功能类.修改学生或者删除学生.ReviseStudent;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

//该类用于绘制登录之后对学生数据进行操作的画面以及书写关于选择操作的代码逻辑
public class OperationPage extends JFrame implements MouseListener {
    JButton addstudent=new JButton("Click here to AddInformation");
    JButton seekstudent=new JButton("Click here to SeekInformation");
    JButton revise =new JButton("Click here to ReviseInformation");
    JButton stats=new JButton("Click here to StatisticsInformation");
    JButton randomstudent=new JButton("Click here to RandomInformation");
    JLabel BackGround=new JLabel(new ImageIcon("D:\\背景图.png"));
    Font f=new Font("宋体",Font.BOLD,15);

    public OperationPage() {
        extracted();
        initImage();
        this.setVisible(true);
    }
    private void extracted(){
        //设置操作界面的长和宽
        this.setSize(800,750);
        this.setTitle("操作页面");
        this.setAlwaysOnTop(true);
        this.setDefaultCloseOperation(3);
        this.setLayout(null);
        this.setLocationRelativeTo(null);

        //添加监听事件
        addstudent.addMouseListener(this);
        seekstudent.addMouseListener(this);
        revise.addMouseListener(this);
        stats.addMouseListener(this);
        randomstudent.addMouseListener(this);
    }
    private void initImage(){
        //绘制总标题
        Font font=new Font("宋体",Font.BOLD,30);
        JLabel tetle=new JLabel("Please choose your operation!");
        tetle.setForeground(Color.white);
        tetle.setBounds(190,10,500,150);
        tetle.setFont(font);
        this.getContentPane().add(tetle);
        //添加 添加学生按钮选择
        addstudent.setBounds(50,150,307,113);
        addstudent.setFont(f);
        addstudent.setBorder(BorderFactory.createLineBorder(Color.pink));
        this.getContentPane().add(addstudent);


        //添加查找学生按钮
        seekstudent.setBounds(50,310,307,113);
        seekstudent.setFont(f);
        seekstudent.setBorder(BorderFactory.createLineBorder(Color.pink));
        this.getContentPane().add(seekstudent);

        //添加录入学生成绩按钮
        revise.setBounds(440,150,307,113);
        revise.setFont(f);
        revise.setBorder(BorderFactory.createLineBorder(Color.pink));
        this.getContentPane().add(revise);

        //添加生成报表按钮
        stats.setBounds(440,310,307,113);
        stats.setFont(f);
        stats.setBorder(BorderFactory.createLineBorder(Color.pink));
        this.getContentPane().add(stats);

        //添加随机生成学生数据按钮
        randomstudent.setBounds(50,470,307,113);
        randomstudent.setFont(f);
        randomstudent.setBorder(BorderFactory.createLineBorder(Color.pink));
        this.getContentPane().add(randomstudent);
        //添加背景图
        BackGround.setBounds(0,0,800,700);
        this.getContentPane().add(BackGround);

    }

    @Override
    public void mouseClicked(MouseEvent e) {
        Object obj=e.getSource();
        if(obj==addstudent){
            //添加学生信息
            System.out.println("我点击了添加学生信息");
            //调用添加学生成绩类，并关闭当前窗口
            new AddStudent(this);
            this.setVisible(true);
        }
        else if(obj==seekstudent){
            System.out.println("我点击了查找学生信息按钮");
            //打开添加学生窗口，关闭当前窗口
            new SeekStudent(this);
            this.setVisible(true);
        }
        else if(obj== revise){
            System.out.println("我点击了修改或删除学生信息按钮");
            new ReviseStudent();
            this.setVisible(true);
        }
        else if(obj==stats){
            System.out.println("我点击了生成报表统计按钮");
            try {
                new GenerateTable(this);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
            this.setVisible(true);
        }
        else if(obj==randomstudent){
            System.out.println("我点击了随机学生数据按钮");
            //调用生成学生数据类，并写入文件和展示表格
            new 学生数据写入文件();
            this.setVisible(true);
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
